<template>
  <div class="flex-center" style="height: 100vh">
    <div class="auth-card">
      <h2 style="margin-bottom: 20px; color: #444">API 搜索系统</h2>
      <el-input
        v-model="apiKey"
        placeholder="请输入 API Key"
        style="width: 300px; margin-bottom: 20px"
        @keyup.enter="handleLogin"
      />
      <el-button type="primary" @click="handleLogin" class="btn"
        >进入系统</el-button
      >
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus";
import { ref } from "vue";
import { useRouter } from "vue-router";

const apiKey = ref("");
const router = useRouter();

const handleLogin = () => {
  if (!apiKey.value.trim()) {
    ElMessage.error("请输入 API Key");
    return;
  }
  localStorage.setItem("apiKey", apiKey.value.trim());
  router.push("/search");
};
</script>

<style scoped>
.auth-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  text-align: center;
}
</style>
